<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>

</html>
<script>
    function deepClone(obj) {
        //检查一个数据是否是一个数组，输出为数组，不是的话就输出对象
        let objClone = Array.isArray(obj) ? [] : {};
        //判断obj 与数值类型是否是对象
        if (obj && typeof obj === 'object') {
            //遍历一遍obj
            for (let key in obj) {
                //判断一下obj的值与数值类型的值是否是对象
                if (obj[key] && typeof obj[key] === 'object') {
                    //递归进行深度拷贝
                    objClone[key] = deepClone(obj[key]);
                } else {
                    //直接拷贝
                    objClone[key] = obj[key]
                }
            }
            console.log('原来的对象:',obj);
            console.log('深拷贝之后:',objClone);
        }
        return objClone;
        
        
    }
   
    deepClone({name:"张三",sex:"20"})


</script>